home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoMainWindow.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  10.2 KB  |  388 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  3.    Copyright (C) 2000-2004 David Faure <faure@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef __ko_main_window_h__
  22. #define __ko_main_window_h__
  23.  
  24. #include <kparts/mainwindow.h>
  25. #include <kfiledialog.h>
  26. #include <koffice_export.h>
  27. #include "KoDocument.h"
  28.  
  29. class QLabel;
  30. class KoView;
  31. class KoMainWindowPrivate;
  32. class KURL;
  33. class KRecentFilesAction;
  34. class KoFilterManager;
  35. class DCOPObject;
  36.  
  37. namespace KParts
  38. {
  39.   class PartManager;
  40. }
  41.  
  42. /**
  43.  * @brief Main window for a KOffice application
  44.  *
  45.  * This class is used to represent a main window
  46.  * of a KOffice component. Each main window contains
  47.  * a menubar and some toolbars.
  48.  *
  49.  * @note This class does NOT need to be subclassed in your application.
  50.  */
  51. class KOFFICECORE_EXPORT KoMainWindow : public KParts::MainWindow
  52. {
  53.     Q_OBJECT
  54. public:
  55.  
  56.     /**
  57.      *  Constructor.
  58.      *
  59.      *  Initializes a KOffice main window (with its basic GUI etc.).
  60.      */
  61.     KoMainWindow( KInstance *instance, const char *_name = 0 );
  62.  
  63.     /**
  64.      *  Destructor.
  65.      */
  66.     ~KoMainWindow();
  67.  
  68.     /**
  69.      * Called when a document is assigned to this mainwindow.
  70.      * This creates a view for this document, makes it the active part, etc.
  71.      */
  72.     virtual void setRootDocument( KoDocument *doc );
  73.  
  74.     /**
  75.      * This is used to handle the document used at start up before it actually
  76.      * added as root document.
  77.      */
  78.     void setDocToOpen( KoDocument *doc );
  79.  
  80.     /**
  81.      * Update caption from document info - call when document info
  82.      * (title in the about page) changes.
  83.      */
  84.     virtual void updateCaption();
  85.  
  86.     /**
  87.      *  Retrieves the document that is displayed in the mainwindow.
  88.      */
  89.     virtual KoDocument* rootDocument() const;
  90.  
  91.     virtual KoView *rootView() const;
  92.  
  93.     virtual KParts::PartManager *partManager();
  94.  
  95.     /**
  96.      * Prints the document
  97.      * @param quick whether the print setup dialog is to be displayed
  98.      **/
  99.     void print(bool quick);
  100.  
  101.     /**
  102.      * The application should call this to show or hide a toolbar.
  103.      * It also takes care of the corresponding action in the settings menu.
  104.      */
  105.     void showToolbar( const char * tbName, bool shown );
  106.  
  107.     /**
  108.      * @return TRUE if the toolbar @p tbName is visible
  109.      */
  110.     bool toolbarIsVisible(const char *tbName);
  111.  
  112.     /**
  113.      * Get hold of the label in the statusbar, to write messages to it.
  114.      * You can also insert other items in the status bar by using QStatusBar::addWidget.
  115.      */
  116.     QLabel * statusBarLabel();
  117.  
  118.     /**
  119.      * Sets the maximum number of recent documents entries.
  120.      */
  121.     void setMaxRecentItems(uint _number);
  122.  
  123.     /**
  124.      * The document opened a URL -> store into recent documents list.
  125.      */
  126.     void addRecentURL( const KURL& url );
  127.  
  128.     /**
  129.      * Load the desired document and show it.
  130.      * @param url the URL to open
  131.      *
  132.      * @return TRUE on success.
  133.      */
  134.     virtual bool openDocument( const KURL & url );
  135.  
  136.     /**
  137.      * Load the URL into this document (and make it root doc after loading)
  138.      *
  139.      * Special method for KoApplication::start, don't use.
  140.      */
  141.     bool openDocument( KoDocument *newdoc, const KURL & url );
  142.  
  143.     virtual DCOPObject * dcopObject();
  144.  
  145.     /**
  146.      * Reloads the recent documents list.
  147.      */
  148.     void reloadRecentFileList();
  149.  
  150.     /**
  151.      * Updates the window caption based on the document info and path.
  152.      */
  153.     virtual void updateCaption( const QString caption, bool mod );
  154.     void updateReloadFileAction(KoDocument *doc);
  155.     void updateVersionsFileAction(KoDocument *doc);
  156.  
  157. signals:
  158.     /**
  159.      * This signal is emitted if the document has been saved successfully.
  160.      */
  161.     void documentSaved();
  162.     /// This signals is emmitted before the save dialog is shown
  163.     void saveDialogShown();
  164.  
  165. public slots:
  166.  
  167.     /**
  168.      * Slot for eMailing the document using KMail
  169.      *
  170.      * This is a very simple extension that will allow any document
  171.      * that is currently being edited to be emailed using KMail.
  172.      */
  173.     void slotEmailFile();
  174.  
  175.     /**
  176.      *  Slot for opening a new document.
  177.      *
  178.      *  If the current document is empty, the new document replaces it.
  179.      *  If not, a new shell will be opened for showing the document.
  180.      */
  181.     virtual void slotFileNew();
  182.  
  183.     /**
  184.      *  Slot for opening a saved file.
  185.      *
  186.      *  If the current document is empty, the opened document replaces it.
  187.      *  If not a new shell will be opened for showing the opened file.
  188.      */
  189.     virtual void slotFileOpen();
  190.  
  191.     /**
  192.      *  Slot for opening a file among the recently opened files.
  193.      *
  194.      *  If the current document is empty, the opened document replaces it.
  195.      *  If not a new shell will be opened for showing the opened file.
  196.      */
  197.     virtual void slotFileOpenRecent( const KURL & );
  198.  
  199.     /**
  200.      *  Saves the current document with the current name.
  201.      */
  202.     virtual void slotFileSave();
  203.  
  204.     /**
  205.      *  Saves the current document with a new name.
  206.      */
  207.     virtual void slotFileSaveAs();
  208.  
  209.     /**
  210.      *  Prints the actual document.
  211.      */
  212.     virtual void slotFilePrint();
  213.  
  214.     /**
  215.      *  Show a print preview
  216.      */
  217.     void slotFilePrintPreview(); // make virtual later
  218.  
  219.     /**
  220.      * Show a dialog with author and document information.
  221.      */
  222.     virtual void slotDocumentInfo();
  223.  
  224.     /**
  225.      *  Closes the document.
  226.      */
  227.     virtual void slotFileClose();
  228.  
  229.     /**
  230.      *  Closes the shell.
  231.      */
  232.     virtual void slotFileQuit();
  233.  
  234.     /**
  235.      *  Configure key bindings.
  236.      */
  237.     virtual void slotConfigureKeys();
  238.  
  239.     /**
  240.      *  Configure toolbars.
  241.      */
  242.     virtual void slotConfigureToolbars();
  243.  
  244.     /**
  245.      *  Post toolbar config.
  246.      * (Plug action lists back in, etc.)
  247.      */
  248.     virtual void slotNewToolbarConfig();
  249.  
  250.     /**
  251.      *  Shows or hides a toolbar
  252.      */
  253.     virtual void slotToolbarToggled( bool toggle );
  254.  
  255.     /**
  256.      * View splitting stuff
  257.      */
  258.     virtual void slotSplitView();
  259.     virtual void slotRemoveView();
  260.     virtual void slotSetOrientation();
  261.  
  262.     /**
  263.      * Close all views
  264.      */
  265.     virtual void slotCloseAllViews();
  266.  
  267.     /**
  268.      * Reload file
  269.      */
  270.     void slotReloadFile();
  271.  
  272.     /**
  273.      * This will call a dialogbox to add version to list of files
  274.      */
  275.     void slotVersionsFile();
  276.  
  277.     /**
  278.      * File --> Import
  279.      *
  280.      * This will call slotFileOpen().  To differentiate this from an ordinary
  281.      * call to slotFileOpen() call @ref isImporting().
  282.      */
  283.     void slotImportFile();
  284.  
  285.     /**
  286.      * File --> Export
  287.      *
  288.      * This will call slotFileSaveAs().  To differentiate this from an ordinary
  289.      * call to slotFileSaveAs() call @ref isExporting().
  290.      */
  291.     void slotExportFile();
  292.  
  293. protected: // protected methods are mostly for koshell, it's the only one deriving from KoMainWindow
  294.  
  295.     /// Helper method for slotFileNew and slotFileClose
  296.     void chooseNewDocument( int /*KoDocument::InitDocFlags*/ initDocFlags );
  297.     /**
  298.      * Special method for KOShell, to allow switching the root
  299.      * document (and its views) among a set of them.
  300.      */
  301.     void setRootDocumentDirect( KoDocument *doc, const QPtrList<KoView> & views );
  302.  
  303.     /**
  304.      * Create a new empty document.
  305.      */
  306.     virtual KoDocument* createDoc() const;
  307.  
  308.     /**
  309.      * Saves the document, asking for a filename if necessary.
  310.      *
  311.      * @param saveas if set to TRUE the user is always prompted for a filename
  312.      *
  313.      * @param silent if set to TRUE rootDocument()->setTitleModified will not be called.
  314.      *
  315.      * @return TRUE on success, false on error or cancel
  316.      *         (don't display anything in this case, the error dialog box is also implemented here
  317.      *         but restore the original URL in slotFileSaveAs)
  318.      */
  319.     virtual bool saveDocument( bool saveas = false, bool silent = false );
  320.  
  321.     virtual void closeEvent( QCloseEvent * e );
  322.     virtual void resizeEvent( QResizeEvent * e );
  323.  
  324.     /**
  325.      * Ask user about saving changes to the document upon exit.
  326.      */
  327.     virtual bool queryClose();
  328.  
  329.     virtual bool openDocumentInternal( const KURL & url, KoDocument * newdoc = 0L );
  330.  
  331.     /**
  332.      * Returns whether or not the current slotFileSave[As]() or saveDocument()
  333.      * call is actually an export operation (like File --> Export).
  334.      *
  335.      * If this is true, you must call KoDocument::export() instead of
  336.      * KoDocument::save() or KoDocument::saveAs(), in any reimplementation of
  337.      * saveDocument().
  338.      */
  339.     bool isExporting() const;
  340.  
  341.     /**
  342.      * Returns whether or not the current slotFileOpen() or openDocument()
  343.      * call is actually an import operation (like File --> Import).
  344.      *
  345.      * If this is true, you must call KoDocument::import() instead of
  346.      * KoDocument::openURL(), in any reimplementation of openDocument() or
  347.      * openDocumentInternal().
  348.      */
  349.     bool isImporting() const;
  350.  
  351.     /**
  352.      * Save the list of recent files.
  353.      */
  354.     void saveRecentFiles();
  355.  
  356.     KRecentFilesAction *recentAction() const { return m_recent; }
  357.  
  358. private:
  359.  
  360.     /**
  361.      * Asks the user if they really want to save the document.
  362.      * Called only if outputFormat != nativeFormat.
  363.      *
  364.      * @return true if the document should be saved
  365.      */
  366.     bool exportConfirmation( const QCString &outputFormat );
  367.  
  368.     void saveWindowSettings();
  369.  
  370.     KRecentFilesAction *m_recent;
  371.  
  372. protected slots:
  373.     virtual void slotActivePartChanged( KParts::Part *newPart );
  374.  
  375. private slots:
  376.     void slotProgress(int value);
  377.     void slotLoadCompleted();
  378.     void slotLoadCanceled (const QString &);
  379.     void slotSaveCompleted();
  380.     void slotSaveCanceled(const QString &);
  381.  
  382. private:
  383.     KoMainWindowPrivate *d;
  384.  
  385. };
  386.  
  387. #endif
  388.